package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.HomeNewProduct;
import com.itheima.manager.SmsHomeNewProductManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class SmsHomeNewProductController {

    @Autowired
    SmsHomeNewProductManager smsHomeNewProductManager;

    //新品推荐分页查询
    @GetMapping("/home/newProduct/list")
    public R findlistByPage(@RequestParam(defaultValue = "1",required = false)Integer pageNum,
                            @RequestParam(defaultValue = "10",required = false)Integer pageSize,
                            @RequestParam(required = false)String productName,
                            @RequestParam(required = false)Integer recommendStatus
                                         ) {

        return smsHomeNewProductManager.findlistByPage(pageNum,pageSize,productName,recommendStatus);

    }

    //添加首页新品
    @PostMapping("/home/newProduct/create")
    public R addNew(@RequestBody HomeNewProduct homeNewProduct)
    {
        return smsHomeNewProductManager.addNew(homeNewProduct);

    }

    //批量删除首页新品
    @PostMapping("/home/newProduct/delete")
    public R delete(@RequestParam Integer [] ids)
    {
        return smsHomeNewProductManager.delete(ids);

    }

    //批量设置状态
    @PostMapping("/home/newProduct/update/recommendStatus")
    public R update(@RequestParam Integer[] ids,Integer recommendStatus)
    {
        return smsHomeNewProductManager.update(ids,recommendStatus);

    }


    @PostMapping("/home/newProduct/update/sort/{id}")
    public R sort(@PathVariable Integer id,@RequestParam(required = false)Integer sort)
    {
        return smsHomeNewProductManager.sort(id,sort);

    }



}
